from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.response import Response
from users.models import UsersModel
from rest_framework import status
from rest_framework.generics import CreateAPIView
from users.userserializer import RegisterSerializer
class UsersTestViews(APIView):
    def post(self,request):
        user = UsersModel.objects.create_user(username="root",email="123@123.com",password="123",is_superuser=1,is_staff=1)
        return Response({"message":"注册成功"})

 # 手机号唯一判断
class MobileApiView(APIView):
    def get(self,request,mobile):
        try:
            UsersModel.objects.get(mobile__exact=mobile)
            return Response({"message":"手机号已存在，请登录或修改密码"},status=status.HTTP_400_BAD_REQUEST)
        except UsersModel.DoesNotExist:
            return Response({"message":"手机号可以注册"},status=status.HTTP_200_OK)
class RegisterViews(CreateAPIView):
    # 校验 create,updata
    serializer_class =  RegisterSerializer
